#!/bin/bash

# 盲盒购买+抽奖接口测试脚本
# 测试重构后的 buy 接口（自动包含抽奖逻辑）

BASE_URL="http://localhost"
API_PATH="/api/blindbox"

echo "=========================================="
echo "  盲盒购买+抽奖接口测试"
echo "=========================================="
echo ""

# 颜色定义
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# 测试参数（需要根据实际情况修改）
UNIACID=1
CUSTOMER_ID=1
BLIND_BOX_ID=1

echo -e "${YELLOW}[测试1] 购买单个盲盒（自动抽奖）${NC}"
echo "----------------------------------------"
curl -X POST "${BASE_URL}${API_PATH}.buy" \
  -H "Content-Type: application/json" \
  -d "{
    \"uniacid\": ${UNIACID},
    \"blind_box_id\": ${BLIND_BOX_ID},
    \"quantity\": 1,
    \"payment_method\": \"wechat\",
    \"shipping_method\": \"package\",
    \"address\": \"{\\\"name\\\":\\\"张三\\\",\\\"telephone\\\":\\\"13800138000\\\",\\\"province_name\\\":\\\"广东省\\\",\\\"city_name\\\":\\\"深圳市\\\",\\\"area_name\\\":\\\"南山区\\\",\\\"detail_address\\\":\\\"科技园\\\"}\",
    \"message\": \"测试订单\"
  }" \
  | python3 -m json.tool
echo ""
echo ""

echo -e "${YELLOW}[测试2] 购买多个盲盒（批量抽奖）${NC}"
echo "----------------------------------------"
curl -X POST "${BASE_URL}${API_PATH}.buy" \
  -H "Content-Type: application/json" \
  -d "{
    \"uniacid\": ${UNIACID},
    \"blind_box_id\": ${BLIND_BOX_ID},
    \"quantity\": 3,
    \"payment_method\": \"wechat\",
    \"shipping_method\": \"package\",
    \"address\": \"{\\\"name\\\":\\\"李四\\\",\\\"telephone\\\":\\\"13800138001\\\",\\\"province_name\\\":\\\"广东省\\\",\\\"city_name\\\":\\\"深圳市\\\",\\\"area_name\\\":\\\"南山区\\\",\\\"detail_address\\\":\\\"科技园\\\"}\",
    \"message\": \"批量测试\"
  }" \
  | python3 -m json.tool
echo ""
echo ""

echo -e "${YELLOW}[测试3] 调用已废弃的 draw 接口${NC}"
echo "----------------------------------------"
curl -X POST "${BASE_URL}${API_PATH}.draw" \
  -H "Content-Type: application/json" \
  -d "{
    \"uniacid\": ${UNIACID},
    \"blind_box_id\": ${BLIND_BOX_ID}
  }" \
  | python3 -m json.tool
echo ""
echo ""

echo -e "${YELLOW}[测试4] 查看抽奖记录${NC}"
echo "----------------------------------------"
curl -X GET "${BASE_URL}${API_PATH}.my_records?uniacid=${UNIACID}" \
  | python3 -m json.tool
echo ""
echo ""

echo -e "${GREEN}=========================================="
echo "  测试完成"
echo "==========================================${NC}"
echo ""
echo "预期结果："
echo "  [测试1] 返回订单信息 + 单个抽奖结果（draw_result、prize）"
echo "  [测试2] 返回订单信息 + 多个抽奖结果（draw_results 数组）"
echo "  [测试3] 返回提示信息：'此接口已废弃...'"
echo "  [测试4] 返回用户的所有抽奖记录"
echo ""
